	<div id="campo_conteudo">
    	<div id="titulo_pagina">
    		Agendamentos 
    		<a href="<?= base_url(); ?>home">
    			<img src="<?= base_url(); ?>images/bt_voltar.png" style="float:right; margin:3px 0 0 0;" /></a>
    	</div>
		<h3 style="line-height:10px">
			Agendamentos Marcados
		</h3>
			<script type="text/javascript">
				var arr_fields = [
				                  {nome:'id',label:'Id', tp_obj: 'hid', tipo : 'int', grid:{name:'id',index:'id', hidden:true, key:true, width:15, def_order:false,order:''}},
				                  {nome:'especialidade',label:'Especialidade', tp_obj: 'txt', tipo : 'str', grid:{name:'especialidade',index:'especialidade', width:170, def_order:false,order:''}},
				                  {nome:'medico',label:'M&eacute;dico', tp_obj: 'txt', tipo : 'str', grid:{name:'medico',index:'medico', width:170, def_order:false,order:''}},
				                  {nome:'paciente',label:'Paciente', tp_obj: 'txt', tipo : 'str', grid:{name:'paciente',index:'paciente', width:170, def_order:false,order:''}},
				                  {nome:'data_consulta',label:'Data da Consulta', tp_obj: 'txt', tipo : 'str', grid:{name:'data_consulta',index:'data_consulta', width:170, def_order:true,order:'asc',formatter:'date'}},
				                  {nome:'horario',label:'Hor&aacute;rio', tp_obj: 'txt', tipo : 'str', grid:{name:'horario',index:'horario', width:170, def_order:false,order:''}},
				                  {nome:'flag_paciente_confirmado',label:'Paciente Confirmado?', tp_obj: 'txt', tipo : 'str', grid:{name:'flag_paciente_confirmado',index:'flag_paciente_confirmado', width:170, def_order:false,order:'', formatter:format_flag}}
					              	];
				var editValue = null;
				$(document).ready(function(){
					var arr_fld_grid = new Array();
					var arr_fld_labels = new Array();
					var fld_sort_name = "";
					var fld_sort_order = "";
					
					for(i=0; i<arr_fields.length; i++)
					{
						if(arr_fields[i].grid != null)
						{
							arr_fld_grid.push(arr_fields[i].grid);
							arr_fld_labels.push(arr_fields[i].label);
							if(arr_fields[i].grid.def_order)
							{
								fld_sort_name = arr_fields[i].grid.name;
								fld_sort_order = arr_fields[i].grid.order;
							}
						}
					}
					
					jQuery("#gridAgenda").jqGrid({
					   	url:'<?php echo base_url()."agendamentos/listAll"?>',
						datatype: "json",
					   	colNames:arr_fld_labels,
					   	colModel:arr_fld_grid,
					   	rowNum:10,
					   	rowList:[5,10,20,30],
					   	height: 'auto',
					   	width:'850',
					   	pager: '#pgridAgenda',
					   	sortname: fld_sort_name,
					    viewrecords: true,
					    sortorder: fld_sort_order,
					    caption:"Agendamentos",
					    onSelectRow: function(id){ 
							if(id && id!==editValue){ 
								editValue=id; 
							} 
						},
						grouping:true,
					   	groupingView : {
					   		groupField : ['data_consulta'],
					   		groupColumnShow : [false],
					   		groupText : ['<b>Data: {0}</b>']
					   	}
					})
					.navGrid('#pgridAgenda',{edit:false,add:false,del:false,search:false,refreshtext:"Refresh"},{},{},{})
					.navSeparatorAdd("#pgridAgenda",{sepclass : "ui-separator",sepcontent: ''})
					.navButtonAdd('#pgridAgenda',{
								   caption:"Confirmar Paciente", 
								   buttonicon:"ui-icon-check", 
								   onClickButton: function(){ 
								   		if(editValue != null)
									   	{
								   			$("#dialog-confirm-agenda").dialog({
								   				resizable: false,
								   				height:160,
								   				width:300,
								   				modal: true,
								   				buttons: {
								   					'Sim': function() {
														$.ajax({
								                    		type: "POST",
								                    		url: '<?php echo base_url()."agendamentos/confirm"?>',
								                    		data: {id:editValue},
								                    		success: function(msg) 
								                    		{
														  		var type = msg.substr(0,3);
																var msgs = msg.substr(4);
				
																if(type != "err")
																{
										   							showMsg(msgs);
																}
																else
																{
																	dialogMessage(msgs,'dialog-message');   
																}
										       					$("#gridAgenda").trigger("reloadGrid");
										       					editValue = null;
								                    		}
														});
								   						$(this).dialog('close');
								   					},
								   					'N\u00e3o': function() {
								   						$(this).dialog('close');
								   					}
								   				}
								   			}); 
									   	}
								   		else
								   		{
											   dialogMessage('Selecione um Agendamento','dialog-message');   
												$("#gridAgenda").trigger("reloadGrid");
									   	}
								   }
								})
				});
			</script>
			<br />
			<br />
			<div align="center">
				<table id="gridAgenda"></table>
				<div id="pgridAgenda"></div>
			</div>
    	<div id="dialog-confirm-agenda" title="Confirmar Agendamento" style="display:none;">
    		<p><span class="ui-icon ui-icon-help" style="float:left; margin:0 7px 20px 0;"></span>Deseja confirmar esse agendamento?</p>
    	</div>
	</div>